package pro.softzhang.algo.lc1400;

import pro.softzhang.algo.common.TreeNode;

public class LC1448_CountGoodNodesInBinaryTree {
    public static void main(String[] args) {

    }

    static
    class Solution {
        public int goodNodes(TreeNode root) {
            return doGoodNodes(root, root.val);
        }

        private int doGoodNodes(TreeNode root, int max) {
            if(root == null) {
                return 0;
            }
            int nodes = 0;
            if(root.val >= max) {
                nodes++;
                max = root.val;
            }
            nodes += doGoodNodes(root.left, max);
            nodes += doGoodNodes(root.right, max);
            return nodes;
        }
    }
}
